<!-- 新增/编辑最低工资 -->
<template>
  <a-modal
    width="40%"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel"
    :mask-closable="false"
    draggable
    title-align="center"
  >
    <template #title>
      <div>信息查看</div>
    </template>
    <a-form :model="formData.data" :rules="rules" ref="refForm">
      <a-form-item label="城市" field="city" show-colon>
        <a-cascader
          :options="citiesJson"
          :field-names="{
            value: 'code',
            label: 'name'
          }"
          v-model="formData.data.city"
        />
      </a-form-item>
      <a-form-item label="类型" field="" show-colon>
        <a-input placeholder="最低工资"></a-input>
      </a-form-item>
      <a-form-item label="工资标准" field="stand" show-colon>
        <a-input-number
          :precision="2"
          :min="0"
          hide-button
          allow-clear
          v-model="formData.data.stand"
        >
          <template #append>
            <span>元/月</span>
          </template>
        </a-input-number>
      </a-form-item>
      <a-form-item
        label="启用日期"
        field="startDate"
        show-colon
        v-model="formData.data.startDate"
      >
        <a-date-picker />
      </a-form-item>
      <a-form-item
        label="结束日期"
        field="endDate"
        show-colon
        v-model="formData.data.endDate"
      >
        <a-date-picker />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script lang="ts" setup>
import citiesJson from '@/assets/json/pc-code.json';

const props = withDefaults(
  defineProps<{
    visible: boolean; // 是否显示对话框
  }>(),
  {
    visible: false
  }
);

const emit = defineEmits(['update:visible']);
let refForm = ref();
const rules = {
  city: [
    {
      required: true,
      message: '请选择'
    }
  ],
  stand: [
    {
      required: true,
      message: '请输入'
    }
  ],
  startDate: [
    {
      required: true,
      message: '请选择'
    }
  ],
  endDate: [
    {
      required: true,
      message: '请选择'
    }
  ]
};

watch(
  () => props.visible,
  (newVal: boolean) => {
    if (newVal) {
      //
    }
  }
);

const formData: any = reactive({
  data: {
    city: undefined, // 城市
    stand: null, // 最低工资
    startDate: undefined, // 启用日期
    endDate: undefined // 结束日期
  }
});

const getData = () => {
  try {
    //
  } catch (error: unknown) {
    console.log(error);
  }
};

// 保存
const handleOk = async () => {
  if (await refForm.value.validate()) {
    return;
  } else {
    emit('update:visible', false);
  }
};

// 取消
const handleCancel = () => {
  emit('update:visible', false);
};
</script>

<style scoped lang="less">
:deep(.arco-input-append) {
  background-color: rgba(237, 239, 253, 0.447);
}
</style>
